/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.then.component.club.di;


import android.app.Application;
import android.arch.persistence.room.Room;

import com.then.architecture.di.AppScope;
import com.then.architecture.utils.LiveDataCallAdapterFactory;
import com.then.architecture.utils.RetryCallAdapterFactory;
import com.then.component.club.api.RemoteService;
import com.then.component.club.applike.ClubAppLike;
import com.then.component.club.db.location.AreaDao;
import com.then.component.club.db.location.CityDao;
import com.then.component.club.db.location.CountryDao;
import com.then.component.club.db.location.LocationDB;
import com.then.component.club.db.location.ProvinceDao;
import com.then.component.club.db.ClubDB;
import com.then.component.club.db.ClubDao;

import dagger.Module;
import dagger.Provides;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

@Module
public class ClubModule {

    private ClubAppLike clubAppLike;

    public ClubModule(ClubAppLike clubAppLike) {
        this.clubAppLike = clubAppLike;
    }

    @AppScope
    @Provides
    RemoteService provideGithubService(OkHttpClient okHttpClient, HttpUrl httpUrl) {
        return new Retrofit.Builder()
                .baseUrl(httpUrl)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RetryCallAdapterFactory.create())
                .addCallAdapterFactory(new LiveDataCallAdapterFactory())
                .build()
                .create(RemoteService.class);
    }

    @AppScope
    @Provides
    ClubDB provideClubDb(Application app) {
        return Room.databaseBuilder(app, ClubDB.class, "AK_POKER.db").build();
    }


    @AppScope
    @Provides
    LocationDB provideAreaDb(Application app) {
        return Room.databaseBuilder(app, LocationDB.class, "area_new.db").build();
    }

    @AppScope
    @Provides
    ClubDao provideClubDao(ClubDB db) {
        return db.clubDao();
    }

    @AppScope
    @Provides
    ProvinceDao provideProvinceDao(LocationDB db) {
        return db.provinceDao();
    }

    @AppScope
    @Provides
    CityDao provideCityDao(LocationDB db) {
        return db.cityDao();
    }

    @AppScope
    @Provides
    CountryDao provideCountryDao(LocationDB db) {
        return db.countryDao();
    }

    @AppScope
    @Provides
    AreaDao provideAreaDao(LocationDB db) {
        return db.areaDao();
    }

 /*
    @Singleton @Provides
    RepoDao provideRepoDao(ClubDB db) {
        return db.repoDao();
    }*/
}
